package com.createidea.cms.service.product;

import java.io.File;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import com.createidea.cms.dao.product.ProductDao;
import com.createidea.cms.to.PictureTo;
import com.createidea.cms.to.ProductTo;
import com.createidea.cms.utils.FileUtil;
import com.createidea.cms.utils.Pager;

public class ProductServiceImpl implements ProductService {
    private ProductDao productDao;
	@Override
	public List<ProductTo> getProductsByStatus(int i) {
		// TODO Auto-generated method stub
		return productDao.getProductsByStatus(i);
	}

	@Override
	public List<ProductTo> getAllEnableProductsByPager(Pager pager, int i) {
		// TODO Auto-generated method stub
		return productDao.getAllEnableProductsByPager(pager,i);
	}

	public ProductDao getProductDao() {
		return productDao;
	}

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	@Override
	public void saveProcut(ProductTo product) {
		// TODO Auto-generated method stub
		product.setCreatedTime(new Timestamp(new Date().getTime()));
		product.setUpdatedTime(new Timestamp(new Date().getTime()));
		product.setStatus(1);
		productDao.saveProcut(product);
	}

	@Override
	public void deleteProcut(String productId) {
		// TODO Auto-generated method stub
		ProductTo product=productDao.getProcut(productId);
		product.setStatus(0);
		productDao.saveProcut(product);
	}

	@Override
	public void updateProduct(ProductTo product) {
		// TODO Auto-generated method stub
		product.setUpdatedTime(new Timestamp(new Date().getTime()));
		productDao.saveProcut(product);
	}

	@Override
	public ProductTo getProduct(String productId) {
		// TODO Auto-generated method stub
		return productDao.getProcut(productId);
	}


	@Override
	public List<ProductTo> getProductsForType(int i, String producttypeId) {
		// TODO Auto-generated method stub
		return productDao.getProductsForType(i, producttypeId);
	}

	@Override
	public List<ProductTo> getProductsForTypeInPager(int i,String producttypeId, Pager pager) {
		// TODO Auto-generated method stub
		return productDao.getProductsForTypeInPager(i,producttypeId, pager);
	}

	@Override
	public void setDefaultPicture(String pictureId, String productId) {
		// TODO Auto-generated method stub
		ProductTo product=productDao.getProcut(productId);
		PictureTo picture=new PictureTo();
		picture.setId(pictureId);
		product.setLogo(picture);
		productDao.saveProcut(product);
	}

	@Override
	public List<ProductTo> getProductsByLan(int i, String lan, int status) {
		// TODO Auto-generated method stub
		return productDao.getProductsByLan(i, lan, status);
	}
	
	@Override
	public List<ProductTo> getProductsByLanInPager(int i, String lan, Pager pager) {
		// TODO Auto-generated method stub
		return productDao.getProductsByLanInPager(i, lan, pager);
	}

}
